package com.atguigu.test07;

import com.atguigu.test06.bean.Department;

import java.util.List;

/**
 * @author haoranlu
 * @project IntelliJ IDEA
 */
public class DepartmentDAOImp1 extends BasicDAOImp2<Department> implements DepartmentDAO {
    @Override
    public void addDepartment(Department dept) {
        String sql = "insert into department values(null,?,?)";
        try {
            update(sql,dept.getDepname(),dept.getDeinfo());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void updateDepartment(Department dept) {
        String sql = "update department set depname=?,deinfo=? where depid=?";
        try {
            update(sql,dept.getDepname(),dept.getDeinfo(),dept.getDepid());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public void deleteDepartment(int depid) {
        String sql = "delete from department where depid = ?";
        try {
            update(sql,depid);
        } catch (Exception e) {
            throw new  RuntimeException(e);
        }
    }

    @Override
    public Department getById(int depid) {
        String sql = "select depid,depname,deinfo from department where depid=?";
        Department t = null;
        try {
            t = getBean(sql, depid);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return t;
    }

    @Override
    public List<Department> getAll() {
        String sql = "select depid,depname,deinfo from department";
        List<Department> list = null;
        try {
            list=getBeanList(sql);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return list;
    }
}
